{extend name="df/tpl/base" /}

{block name="area_head"}
<style>
/*a{ color:#333 !important;cursor: pointer; }*/
.tools-dir .layui-btn{ text-align: left !important; }
</style>
<!-- ueditor -->
<script type="text/javascript" charset="utf-8" src="__PUBLIC__static/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__static/ueditor/1.4.3/ueditor.all.min.js"> </script>
{/block}

{block name="area_body"}
<div class="page-header">
  <div class="page-title"><i></i>
    文章 {$op}
  </div>
</div>
<!-- 工具箱 -->
<ul class="tools-dir" style="display: none;">
  <li><a id="js-build-kwords" class="layui-btn layui-btn-primary layui-btn-fluid">生成关键词<em>new</em></a></li>
  <li><a id="js-build-excerpt" class="layui-btn layui-btn-primary layui-btn-fluid"><cite>生成摘要</cite><span class="layui-badge-dot"></span></a></li>
</ul>
{include file="df/tpl/set_form"}
{include file="df/tpl/pic_select"}
{/block}

{block name="area_foot"}
<script>
// page init
layui.use(['rb','form','datetimepicker'], function(){
  var layer = layui.layer,
  form = layui.form,
  rb = layui.rb,
  $ = layui.$;

  rb.log('page','init');
  // 工具箱
  var siteDir = $('.tools-dir');
  if(siteDir[0] && $(window).width() > 750){
    layer.ready(function(){
      layer.open({
        type: 1
        ,zIndex:3
        ,content: siteDir
        ,skin: 'layui-layer-lan'
        ,area: 'auto'
        ,maxHeight: $(window).height() - 250
        ,title: '工具箱<span class="layui-badge-dot" style="left: 6px;"></span>'
        //,closeBtn: false
        ,offset: ['250px','750px']
        // ,offset: 'r'
        ,shade: false
        ,success: function(layero, index){
          layer.style(index, {
            marginLeft: -15
          });
        }
      });
    });
    // siteDir.find('li').on('click', function(){
    //   var othis = $(this);
    //   othis.find('a').addClass('layui-this');
    //   othis.siblings().find('a').removeClass('layui-this');
    // });
  }
  // datetimepicker
  $(".js-datetime-picker").each(function(index, el) {
    var $el = $(el);
    var fmt = $el.data('format');
    $el.datetimepicker({
      lang: 'ch',
      timepicker:fmt.indexOf("i") != -1,
      datepicker:fmt.indexOf("m") != -1,
      // step: 5,
      format:fmt,
      allowBlank : true,
    });
  });
  // ueditor
  var ue = UE.getEditor('jsf-content',{
    toolbars:[
      ['fullscreen', 'source', 'undo', 'redo', 'bold','italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', '|','lineheight'
     , 'fontsize','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', 'insertimage','emotion','link', 'unlink', 'anchor', '|','map', 'preview',  'drafts','forecolor','backcolor'
      ]
  ]});
  // 自动生成简介
  $('#js-build-excerpt').click(function(e) {
    var con = ue.getContentTxt().trim();
    //取内容的前50个字做简介
    if(con){
      $('#jsf-excerpt').val(con.substr(0,50));
    }else{
      rb.error('内容未填写');
    }
  });
  // 自动生成关键词
  var ajaxUrl = "{:url(CONTROLLER_NAME.'/ajax_scws')}",kword;
  $('#js-build-kwords').click(function(e) {
    layui.stope(e);
    var kword = $('#jsf-title').val();
    if(kword){
      // console.log(kword);
      $.post(ajaxUrl, { kword: kword }, function(d) {
        rb.ajaxErr(d,function(d){
          $('#jsf-kwords').val(d.data);
        });
      });
    }else{
      rb.error('标题未填写!');
    }
  })

});
</script>
{/block}